package cn.wolfcode.wms.web.controller;


import cn.wolfcode.wms.domain.StockIncomeBill;
import cn.wolfcode.wms.domain.Depot;
import cn.wolfcode.wms.query.StockIncomeBillQueryObject;
import cn.wolfcode.wms.service.IStockIncomeBillService;
import cn.wolfcode.wms.service.IDepotService;
import cn.wolfcode.wms.util.JSONResult;
import cn.wolfcode.wms.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("stockIncomeBill")
public class StockIncomeBillController {
    @Autowired
    private IStockIncomeBillService stockIncomeBillService;
    @Autowired
    private IDepotService depotService;

    @RequestMapping("list")
    public String list(@ModelAttribute("qo") StockIncomeBillQueryObject qo, Model model){
        PageResult pageResult = stockIncomeBillService.queryResult(qo);
        model.addAttribute("result",pageResult);
        model.addAttribute("depots",depotService.selectList());
        return "stockIncomeBill/list";
    }
    @RequestMapping("audit")
    public String audit(Long id){

        stockIncomeBillService.audit(id);

        return "redirect:/stockIncomeBill/list.do";
    }

    @RequestMapping("input")
    public String input(Model model,Long id){

        if (id != null) {
            StockIncomeBill bill = stockIncomeBillService.get(id);
            model.addAttribute("entity",stockIncomeBillService.get(id));
        }
        model.addAttribute("depots",depotService.selectList());
        return "stockIncomeBill/input";
    }

    @RequestMapping("view")
    public String view(Model model,Long id){

        if (id != null) {
            StockIncomeBill bill = stockIncomeBillService.get(id);
            model.addAttribute("entity",stockIncomeBillService.get(id));
        }
        StockIncomeBill bill = stockIncomeBillService.get(id);
        model.addAttribute("depot",depotService.get(bill.getDepot().getId()));
        return "stockIncomeBill/view";
    }

    @RequestMapping("delete")
    @ResponseBody
    public Object delete(Long id){

        stockIncomeBillService.delete(id);

        return new JSONResult();
    }

    @RequestMapping("saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(StockIncomeBill d){

        stockIncomeBillService.saveOrUpdate(d);

        return new JSONResult();
    }

}
